package com.audaque.springboot.foshanupload.web.mpgui.impl;

import cn.hutool.core.util.StrUtil;
import com.audaque.springboot.foshanupload.web.mpgui.GeneratorMain;
import com.github.davidfantasy.mybatisplus.generatorui.mbp.NameConverter;
import com.google.common.base.Strings;

/**
 * @author zgb
 * @desc ...
 * @date 2023-03-29 19:26:01
 */

public class MyNameConverter implements NameConverter {


    public String entityNameConvert(String tableName) {
        if (Strings.isNullOrEmpty(tableName)) {
            return "";
        } else {
            if (tableName.contains(GeneratorMain.dataSourceEnum.getSuffix())) {
                //去掉前缀
                String replaceFirst = tableName.replaceFirst(GeneratorMain.dataSourceEnum.getSuffix(), "");
                tableName = replaceFirst;
            }
            if (tableName.contains("_")) {
                //下划线转驼峰
                String s = StrUtil.toCamelCase(tableName.toLowerCase());
                tableName = s;
            }
            //首字母大写
            tableName = StrUtil.upperFirst(tableName);
            return tableName;
        }
    }

    public String propertyNameConvert(String fieldName) {
        if (Strings.isNullOrEmpty(fieldName)) {
            return "";
        } else {
            //下划线转驼峰
            String s = fieldName.contains("_") ? StrUtil.toCamelCase(fieldName.toLowerCase()) : fieldName;
            return s;
        }
    }

    public String mapperNameConvert(String entityName) {
        return entityName + "Mapper";
    }

    public String mapperXmlNameConvert(String entityName) {
        return entityName + "Mapper";
    }

    public String serviceNameConvert(String entityName) {
        return "I" + entityName + "Service";
    }

    public String serviceImplNameConvert(String entityName) {
        return entityName + "ServiceImpl";
    }

    public String controllerNameConvert(String entityName) {
        return entityName + "Controller";
    }

    public String customFileNameConvert(String fileType, String entityName) {
        return entityName + fileType;
    }
}
